import { load, isLogin } from "/admin/util/LoadView.js";
load('index');
let user = isLogin();
// console.log(user);
document.querySelector('.userprofile').innerHTML = `
<img src='${user.photo}' style="width:100px;height:100px;border-radius:50%;"/>
<div>
    <div>${user.username}</div>
    <div><pre>${user.userintro || "这个人很懒，什么也没留下"}</pre></div>
</div>
`
let category = ["最新动态", "典型案例", "通知公告"]
async function analyse() {
    let res = await fetch("http://localhost:3000/news").then(res => res.json())
    console.log("返回结果",_.groupBy(res, item => item.category))
    let obj = _.groupBy(res, item => item.category)
    //该对象的键是将数组中的元素通过fn函数处理后得到的结果，值是符合该键的元素组成的数
    let chartData = []
    for (let i in obj) {
        chartData.push({
            // name: category[obj[i][0].category],
            name: category[i],
            value: obj[i].length
        })
    }
    console.log("传递数据",chartData)
    renderEcharts(chartData)
}
function renderEcharts(chartData) {
    var myChart = echarts.init(document.getElementById('main'));
    // 指定图表的配置项和数据
    var option = {
        title: {
            text: '当前用户发布的新闻',
            subtext: '不同类别占比',
            left: 'center'
        },
        tooltip: {
            trigger: 'item'
        },
        legend: {
            orient: 'vertical',
            left: 'left'
        },
        series: [
            {
                name: 'Access From',
                type: 'pie',
                radius: '50%',
                data: chartData,
                emphasis: {
                    itemStyle: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }
        ]
    };
    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
}
analyse()